package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.activity.seacraft.SeacraftSouthSeaCrossUnionData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eUnionPosition;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.entity.rank.stronghold.CrossActivityUnionRank;
import com.yanqu.road.logic.bussiness.activity.SeacraftSouthSeaBusiness;
import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.logic.cross.CrossGeneralActivityUnionRankModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.pb.crossunion.activity.CrossUnionActivityRankDataProto;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;
import com.yanqu.road.server.manager.activity.CrossGeneralActivityRankMgr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/10 16:04
 */
public class SeacraftSouthSeaActivityRank extends BaseCrossRank {

    public SeacraftSouthSeaActivityRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        //个人排行补发按新的商会活动分组走
//        Map<Integer, CrossActivityRankListModel> modelMap = ActivityRankMgr.getCrossActivityNewRankListModelMap(activityId);
//        if (modelMap != null) {
//            for (Map.Entry<Integer, CrossActivityRankListModel> entry : modelMap.entrySet()) {
//                CrossActivityRankListModel rankListModel = entry.getValue();
//                int conditionType = rankListModel.getConditionType();
//                if(conditionType != eGamePlayerEventType.SeacraftPirateRiotScoreRank.getValue() && conditionType != eGamePlayerEventType.SeacraftSouthSeaUserScoreRank.getValue()){
//                    continue;
//                }
//                int rank = 0;
//                for (CrossUserRank rankData : rankListModel.getRankList()) {
//                    long userId = rankData.getUserId();
//                    rank++;
//                    addUserRankData(msg, conditionType, userId, rank);
//                }
//            }
//        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        // 海盗之乱的排行
        //海盗之乱的排行另外处理
//        HashMap<Integer, CrossGeneralActivityUnionRankModel> model = CrossGeneralActivityRankMgr.getCrossActivityUnionRankListModel(activityId);
//        for (Map.Entry<Integer, CrossGeneralActivityUnionRankModel> entry : model.entrySet()) {
//            CrossGeneralActivityUnionRankModel rankListModel = entry.getValue();
//            int conditionType = rankListModel.getConditionType();
//            // 商会的这里只发海盗之乱的
//            if (conditionType != eGamePlayerEventType.SeacraftPirateRiotUnionScoreRank.getValue()) {
//                continue;
//            }
//            int rank = 0;
//            for (CrossActivityUnionRank rankData : rankListModel.getRankList()) {
//                String unionUid = rankData.getUnionUid();
//                rank++;
//                addUnionRankData(msg, conditionType, unionUid, rank);
//            }
//        }
        // 南海丝路联盟排行
        Map<String, SeacraftSouthSeaCrossUnionData> map = SeacraftSouthSeaBusiness.getSeacraftSouthSeaCrossUnionDataMap(activityId);
        for (SeacraftSouthSeaCrossUnionData item : map.values()){
            if(item.getUnionBaseInfo() != null){
                AutoSendRewardProto.UnionRankMsg.Builder builder = AutoSendRewardProto.UnionRankMsg.newBuilder();
                builder.setConditionType(eGamePlayerEventType.SeacraftSouthSeaUnionRank.getValue());
                builder.setUnionId(item.getUnionId());
                builder.setRank(item.getRank());
                for (Long memberId : item.getMemberSet()) {
                    int post = eUnionPosition.Member.getValue();
                    if(memberId == item.getUnionBaseInfo().getMasterUserId()){
                        post = eUnionPosition.Master.getValue();
                    }
                    builder.addPosList(CrossUnionActivityRankDataProto.CrossUnionMemberPosDataMsg.newBuilder().setUserId(memberId).setPos(post));
                }
                msg.addData(builder);
            }
        }
        return msg;
    }

    // TODO FIX-cwq 4.6版本可以删除
    @Deprecated
    public AutoSendRewardProto.CrossUnionRankWithUnionInfoMsg.Builder sendCrossUnionWithUnionInfoRank(){
        AutoSendRewardProto.CrossUnionRankWithUnionInfoMsg.Builder builder = AutoSendRewardProto.CrossUnionRankWithUnionInfoMsg.newBuilder();
//        Map<String, SeacraftSouthSeaCrossUnionData> map = SeacraftSouthSeaBusiness.getSeacraftSouthSeaCrossUnionDataMap(activityId);
//        builder.setActivityId(activityId);
//        for (SeacraftSouthSeaCrossUnionData item : map.values()){
//            if(item.getUnionBaseInfo() != null){
//                addUnionRankWithUnionInfoData(builder, eGamePlayerEventType.SeacraftSouthSeaUnionRank.getValue(),item.getUnionId(),item.getRank(),item.getUnionBaseInfo().getMasterUserId(),new ArrayList<>(item.getMemberSet()));
//            }
//        }
        return builder;
    }

}
